import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
Vue.use(VueRouter)
// 重写push和replace方法 解决传递重复参数跳转错误的问题
let origPush = VueRouter.prototype.push
let origReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function(location,resolve,reject){
  if(resolve && reject){
    origPush.call(this,location,resolve,reject)
  }else{
    origPush.call(this, location, () => {}, () => {})
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    origReplace.call(this, location, resolve, reject)
  } else {
    origReplace.call(this, location, () => {}, () => {})
  }
}

export default new VueRouter({
  routes:[
    //资源的重定向
    {
      path:'*',
      redirect:'/home',
    },

    {
      path:'/home',
      component:Home,
      name:'home',
      meta: {
        show: true
      }
    },
    {
      path: '/search',
      component: Search,
      name: 'search',
      meta: {
        show: true
      }
    },
    {
      path: '/login',
      component: Login,
      name:'login',
      meta: {
        show: false
      }
    },
    {
      path: '/register',
      component: Register,
      name:'register',
      meta: {show: false}
    },
  ]
})